<template>
  <el-card class="box-card" style="margin-top: 30px">
    <div slot="header" class="clearfix">
      <el-tabs class="tab" v-model="activeName">
        <el-tab-pane label="销售额" name="sale">
          <el-row :gutter="10">
        <el-col :span="18">
          <div class="charts1" ref="charts1"></div>
        </el-col>
        <el-col :span="6" class="right-mid">
            <h3>门店{{title}}排名:</h3>
            <ul>
                <li>
                    <span class="rindex">1</span>
                    <span>肯德基</span>
                    <span class="rvalue">232.335</span>
                </li>
                <li>
                       <span class="rindex">2</span>
                    <span>麦当劳</span>
                    <span class="rvalue">133.665</span>
                </li>
                <li>
                       <span class="rindex">3</span>
                    <span>华莱士</span>
                    <span class="rvalue">125.666</span>
                </li>
                <li>
                       <span>4</span>
                    <span>米多多</span>
                    <span class="rvalue">98.660</span>
                </li>
                <li>
                    <span>5</span>
                    <span>胖师傅</span>
                    <span class="rvalue">88.123</span>
                </li>
                <li>
                    <span>6</span>
                    <span>螺蛳粉</span>
                    <span class="rvalue">78.338</span>
                </li>
                <li>
                    <span>7</span>
                    <span>佬周记</span>
                    <span class="rvalue">53.669</span>
                </li>
            </ul>
        </el-col>
      </el-row>
        </el-tab-pane>
        <el-tab-pane label="访问量" name="visit">
               <el-row :gutter="10">
        <el-col :span="18">
          <div class="charts2" ref="charts2"></div>
        </el-col>
        <el-col :span="6" class="right-mid">
            <h3>门店{{title}}排名:</h3>
            <ul>
                <li>
                    <span class="rindex">1</span>
                    <span>麦当劳</span>
                    <span class="rvalue">232.662</span>
                </li>
                <li>
                       <span class="rindex">2</span>
                    <span>肯德基</span>
                    <span class="rvalue">211.335</span>
                </li>
                <li>
                       <span class="rindex">3</span>
                    <span>米多多</span>
                    <span class="rvalue">187.556</span>
                </li>
                <li>
                       <span>4</span>
                    <span>胖师傅</span>
                    <span class="rvalue">88.560</span>
                </li>
                <li>
                    <span>5</span>
                    <span>华莱士</span>
                    <span class="rvalue">55.163</span>
                </li>
                <li>
                    <span>6</span>
                    <span>螺蛳粉</span>
                    <span class="rvalue">33.338</span>
                </li>
                <li>
                    <span>7</span>
                    <span>佬周记</span>
                    <span class="rvalue">25.669</span>
                </li>
            </ul>
        </el-col>
      </el-row>
        </el-tab-pane>
      </el-tabs>
      <div class="right">
        <a href="#"><span @click="getToday">今日</span></a>
        <a href="#"><span @click="setWeek">本周</span></a>
        <a href="#"><span @click="setMonth">本月</span></a>
        <a href="#"><span @click="setYear">本年</span></a>
        <el-date-picker
          class="date"
          v-model="date"
          type="datetimerange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          size="mini"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </div>
    </div>
    <div >
      
    </div>
  </el-card>
</template>

<script>
import dayjs from 'dayjs'
import * as echarts from "echarts";
export default {
  name: "",
  data() {
    return {
      activeName: "sale",
      mycharts1:null,
      mycharts2:null,
      date:[]
    };
  },
  mounted() {
    this.mycharts1 = echarts.init(this.$refs.charts1);
    this.mycharts1.setOption({

      title: {
        text: this.title+"趋势",
        left: "center",
      },
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "shadow",
        },
      },
      grid: {
        left: "3%",
        right: "4%",
        bottom: "3%",
        containLabel: true,
      },
      xAxis: [
        {
          type: "category",
          data: [
            "一月",
            "二月",
            "三月",
            "四月",
            "五月",
            "六月",
            "七月",
            "八月",
            "九月",
            "十月",
            "十一月",
            "十二月",
          ],
          axisTick: {
            alignWithLabel: true,
          },
        },
      ],
      yAxis: [
        {
          type: "value",
        },
      ],
      series: [
        {
          name: "Direct",
          type: "bar",
          barWidth: "60%",
          data: [10, 52, 200, 334, 390, 330, 220, 110, 98, 320, 35, 300],
          color: "green",
        },
      ],
    });
     this.mycharts2 = echarts.init(this.$refs.charts2);
    this.mycharts2.setOption({
      title: {
        text: this.title+"趋势",
        left: "center",
      },
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "shadow",
        },
      },
      grid: {
        left: "3%",
        right: "4%",
        bottom: "3%",
        containLabel: true,
      },
      xAxis: [
        {
          type: "category",
          data: [
            "一月",
            "二月",
            "三月",
            "四月",
            "五月",
            "六月",
            "七月",
            "八月",
            "九月",
            "十月",
            "十一月",
            "十二月",
          ],
          axisTick: {
            alignWithLabel: true,
          },
        },
      ],
      yAxis: [
        {
          type: "value",
        },
      ],
      series: [
        {
          name: "Direct",
          type: "bar",
          barWidth: "60%",
          data: [169, 82, 280, 254, 148, 230, 320, 90, 38, 220,135,230],
          color: "skyblue",
        },
      ],
    });
  
  },
  watch:{
    title(){
      this.mycharts.setOption({
        title:{
          text: this.title+"趋势",
        }
      })
    }
  },
  computed:{
    title(){
      return this.activeName == 'sale'?'销售额':'访问量'
    }
  },
  methods:{
    getToday(){
        const day = dayjs().format('YYYY-MM-DD')
        this.date = [day,day]
    },
    setWeek(){
        const start = dayjs().day(1).format('YYYY-MM-DD')
        const end = dayjs().day(7).format('YYYY-MM-DD')
        this.date = [start,end]
    },
    setMonth(){
        const start = dayjs().startOf('month').format('YYYY-MM-DD')
        const end = dayjs().endOf('month').format('YYYY-MM-DD')
        this.date = [start,end]
    },
    setYear(){
        const start = dayjs().startOf('year').format('YYYY-MM-DD')
        const end = dayjs().endOf('year').format('YYYY-MM-DD')
         this.date = [start,end]
    }
  }
};
</script>

<style scoped>
.clearfix {
  position: relative;
  display: flex;
  justify-content: space-between;
}
.tab {
  width: 100%;
}
.right {
  position: absolute;
  right: 0px;
}
.date {
  width: 300px;
  margin-left: 20px;
}
span {
  margin-right: 20px;
}
a span:hover {
  color: #409eff;
}
.charts1 {
  width: 1003px;
  height: 400px;
}
.charts2 {
   width: 1003px;
  height: 400px;
}
ul{
    list-style: none;
    width: 100%;
    height: 400px;
}
.right-mid{
    margin-top: 10px;
}
ul li{
    margin: 0;
    padding: 0;
    margin: 10px 0;
    height: 10%;
}
.rindex {
  float: left;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: black;
  color: white;
  text-align: center;
}
ul li{
  float: right;
}
ul{
  position: relative;
  right: 40px;
}
</style>